<template>
  <div>
    <el-tabs v-model="activeKey" @tab-click="handleTab">
      <el-tab-pane label="待审核" name="1"> </el-tab-pane>
      <el-tab-pane label="已审核" name="2"></el-tab-pane>
    </el-tabs>
    <el-card style="min-width: 1200px">
      <div v-show="eventTab == '1'" class="tableSelectWrap">
        <el-form ref="refundForm" :model="commandForm" label-width="100px">
          <el-row>
            <el-col :span="7" style="display: flex" v-if="activeKey=='2'">
              <el-form-item prop="dateType" label-width="0">
                <el-select
                  class="leftSelect"
                  v-model="commandForm.dateType"
                  style="width: 100px; border-radius: none"
                  placeholder="选择时间"
                >
                <el-option :label="'退款发起时间'" value="1"></el-option>
                  <el-option label="审核完成时间" value="2"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item prop="date" label-width="0" style="flex: 1">
                <el-date-picker
                  v-model="commandForm.date"
                  style="width: 100%; border-radius: 0px; margin-top: 1px"
                  type="datetimerange"
                  start-placeholder="开始时间"
                  :default-time="['00:00:00', '23:59:59']"
                  end-placeholder="结束时间"
                  :clearable="false"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="7" v-else>
              <el-form-item label="选择时间" prop="date">
                <el-date-picker
                  v-model="commandForm.date"
                  style="
                    width: 100%;
                    border-radius: 0 4px 4px 0;
                    margin-top: 1px;
                  "
                  type="datetimerange"
                  start-placeholder="开始时间"
                  :default-time="['00:00:00', '23:59:59']"
                  end-placeholder="结束时间"
                  clearable
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1" v-if="activeKey=='2'">
              <el-form-item label="审核状态" prop="status">
                <el-select
                  v-model="commandForm.status"
                  style="width: 100%"
                  placeholder="请选择审核状态"
                  clearable
                >
                  <el-option
                    v-for="item of refundStateList"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1" style="min-width: 170px; margin-bottom: 18px">
              <el-button class="width120" @click="resetForm('refundForm')"
                >重置</el-button
              >
              <el-button
                type="primary"
                class="width120"
                @click="()=>{
               this.dataForm=JSON.parse(JSON.stringify(this.commandForm));
               this.handleQuery()
              }"
                >查询</el-button
              >
            </el-col>
          </el-row>
          <el-row>
 
          </el-row>
          <el-row>
            <el-button
              @click="exchangeEventTab"
              icon="el-icon-search"
              class="searchBtn"
              >精确搜索</el-button
            >
          </el-row>
        </el-form>
      </div>
      <div v-show="eventTab == '2'" class="tabWrap">
        <el-input
          class="search"
          clearable
          v-model="commandForm.searchVal"
          @keyup.enter.native="()=>{
           this.tabRefundIndex=='1'?this.commandForm.merchantChargeNo=this.commandForm.searchVal:this.commandForm.batchNo=this.commandForm.searchVal
               this.dataForm=JSON.parse(JSON.stringify(this.commandForm));
               this.globalQuery()
              }"
          :placeholder="
            tabRefundIndex === '1' ? '请输入商户订单号' : '请输入批次号'
          "
        >
        </el-input>
        <div class="searBtn">
          <el-button type="primary" @click="()=>{
             this.tabRefundIndex=='1'?this.commandForm.merchantChargeNo=this.commandForm.searchVal:this.commandForm.batchNo=this.commandForm.searchVal
               this.dataForm=JSON.parse(JSON.stringify(this.commandForm));
               this.globalQuery()
              }">搜索</el-button>
        </div>
        <div class="backWrap" @click="exchangeEventTab">
          <span>筛选搜索</span>
          <img src="@/assets/imgs/setting/down1.png" />
        </div>
      </div>
    </el-card>
    <el-card v-if="activeKey=='1'"
      class="textBox"
      style="min-width: 1200px; margin-bottom: -5px; margin-top: 15px"
    >
    <span class="numBox">
        <span>待审核总额</span>
        <span class="symbol">￥</span>
        <span class="num">{{auditInfo ? auditInfo.totalAmountStr : "0.00"
        }}</span>
      </span>
      <span class="numBox">
        <span>待审核笔数</span>
        <span class="num symbol">{{
          auditInfo ? auditInfo.recordSize : "0"
        }}</span>
        <span> 笔</span>
      </span>

    </el-card>
    <el-card v-else
      class="textBox"
      style="min-width: 1200px; margin-bottom: -5px; margin-top: 15px"
    >
    <span class="numBox">
        <span>已审核总额</span>
        <span class="symbol">￥</span>
        <span class="num">{{auditInfo ? auditInfo.totalAmountStr : "0.00"
        }}</span>
      </span>
      <span class="numBox">
        <span>已审核笔数</span>
        <span class="num symbol">{{
          auditInfo ? auditInfo.recordSize : "0"
        }}</span>
        <span> 笔</span>
      </span>

    </el-card>
    <el-card style="margin-top: 15px; min-width: 1200px">
      <div class="switch">
        <div>
<el-button class="width120" :class="tabRefundIndex=='1'?'allbtn':''" @click="tabRefundFn('1')">单笔退款</el-button>
<el-button class="width120" :class="tabRefundIndex=='2'?'allbtn':''" @click="tabRefundFn('2')">批量退款</el-button>
        </div>
        <div>
          <el-button
            class="width120"
            type="primary"
            @click="btnShow = true"
            v-if="tabRefundIndex === '1' && !btnShow && buttonRole && activeKey=='1'"
            >批量处理</el-button
          >
          <div v-if="tabRefundIndex === '1' && btnShow && buttonRole && activeKey=='1'">
            <el-button
              class="width120"
              @click="
                btnShow = false;
                multipleSelection = [];
                $refs.multipleTable.clearSelection();
              "
              >取消</el-button
            >
            <el-button
              class="width120"
              type="primary"
              @click="batchAudit('success_approval', true)"
              >批量同意</el-button
            >
            <el-button
              class="width120"
              type="danger"
              @click="batchAudit('fail_approval')"
              >批量拒绝</el-button
            >
          </div>
        </div>
      </div>
      <div v-if="activeKey=='1'">
        <el-table
        :height="fixedTableHeight"
        ref="multipleTable"
        :data="dataList"
        :key="tabRefundIndex"
        @selection-change="handleSelectionChange"
      >
        <template slot="empty">
          <el-empty
            :image="require('@/assets/imgs/middleWork/k1.png')"
            :image-size="80"
            description="暂无相关数据"
          ></el-empty>
        </template>
        <el-table-column
          show-overflow-tooltip
          type="selection"
          width="55"
          v-if="activeKey === '1' && btnShow"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="gmtCreated"
          align="center"
          label="退款发起时间"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.gmtCreated ? scope.row.gmtCreated : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '1'"
          prop="merchantChargeNo"
          align="center"
          label="商户订单号"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.merchantChargeNo ? scope.row.merchantChargeNo : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '2'"
          prop="batchNo"
          align="center"
          label="批次号"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.batchNo ? scope.row.batchNo : "-" }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '1'"
          prop="subject"
          align="center"
          label="商品名称"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.subject ? scope.row.subject : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '1'"
          prop="channelType"
          align="center"
          label="支付渠道"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.channelType ? scope.row.channelType : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '2'"
          prop="tradeSize"
          align="center"
          label="总笔数"
        >
          <template slot-scope="scope">
            <span
            >{{ scope.row.tradeSize }}</span
            >
            <!-- style="color: #03bfc6; cursor: pointer" -->
              <!-- @click="showDetails(scope.row.batchNo, scope.row.status)" -->
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '2'"
          prop="refundAmountStr"
          align="center"
          label="总金额/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{
                scope.row.refundAmountStr ? scope.row.refundAmountStr : "0.00"
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '1'"
          prop="refundAmountStr"
          align="center"
          label="退款金额/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.refundAmountStr ? scope.row.refundAmountStr : "0.00" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="submitUser"
          align="center"
          label="退款发起人"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.submitUser ? scope.row.submitUser : "-" }}
            </div>
          </template>
        </el-table-column>
  
        <el-table-column
          show-overflow-tooltip
          prop="refundRemark"
          align="center"
          label="退款理由"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.refundRemark ? scope.row.refundRemark : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column  align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="handleDetails(scope.row)"
              >详情</el-button
            >
            <el-button
              type="text"
              v-if="buttonRole"
              @click="
                tabRefundIndex == '1'
                  ? handleAudit(scope.row, 'success_approval')
                  : batchEdit('success_approval', scope.row.id)
              "
              >同意</el-button
            >
            <el-button
              type="text"
              v-if="buttonRole"
              style="color: #f56c6c"
              @click="
                tabRefundIndex == '1'
                  ? handleAudit(scope.row, 'fail_approval')
                  : batchEdit('fail_approval', scope.row.id)
              "
              >拒绝</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      </div>
      <div v-if="activeKey=='2'">
        <el-table
        :height="fixedTableHeight"
        :data="dataList"
      >
        <template slot="empty">
          <el-empty
            :image="require('@/assets/imgs/middleWork/k1.png')"
            :image-size="80"
            description="暂无相关数据"
          ></el-empty>
        </template>
        <el-table-column
          show-overflow-tooltip
          prop="gmtCreated"
          align="center"
          label="退款发起时间"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.gmtCreated ? scope.row.gmtCreated : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="auditTime"
          align="center"
          label="审核完成时间"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.auditTime ? scope.row.auditTime : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '1'"
          prop="merchantChargeNo"
          align="center"
          label="商户订单号"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.merchantChargeNo ? scope.row.merchantChargeNo : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '2'"
          prop="batchNo"
          align="center"
          label="批次号"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.batchNo ? scope.row.batchNo : "-" }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '1'"
          prop="subject"
          align="center"
          label="商品名称"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.subject ? scope.row.subject : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '1'"
          prop="channelType"
          align="center"
          label="支付渠道"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.channelType ? scope.row.channelType : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '2'"
          prop="tradeSize"
          align="center"
          label="总笔数"
        >
          <template slot-scope="scope">
            <span
              >{{ scope.row.tradeSize }}</span
              >
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '2'"
          prop="refundAmountStr"
          align="center"
          label="总金额/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{
                scope.row.refundAmountStr ? scope.row.refundAmountStr : "0.00"
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          v-if="tabRefundIndex === '1'"
          prop="refundAmountStr"
          align="center"
          label="退款金额/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.refundAmountStr ? scope.row.refundAmountStr : "0.00" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="submitUser"
          align="center"
          label="退款发起人"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.submitUser ? scope.row.submitUser : "-" }}
            </div>
          </template>
        </el-table-column>
  
        <el-table-column
          show-overflow-tooltip
          prop="refundRemark"
          align="center"
          label="退款理由"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.refundRemark ? scope.row.refundRemark : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="auditUser"
          align="center"
          label="审核人"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.auditUser ? scope.row.auditUser : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="auditStatusName"
          align="center"
          label="审核结果"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.auditStatusName ? scope.row.auditStatusName : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column  align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="handleDetails(scope.row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      </div>
  
    </el-card>
    <el-pagination
      layout="prev, pager, next, sizes, jumper"
      :page-sizes="[10, 20, 30, 40]"
      :page-size.sync="pageSize"
      :current-page.sync="pageNum"
      :total="total"
      @current-change="pageCurrentChangeHandle"
      @size-change="pageSizeChangeHandle"
    >
    </el-pagination>

    <el-dialog :visible.sync="detailsVisible" top="30vh" width="50%">
      <div class="detailscss">
        <div class="title">批量审核</div>
        <div class="tag">
          <span>退款批次号</span>
          <span class="batchNo">{{ batchNo }}</span>
        </div>
        <el-descriptions
          :column="4"
          direction="vertical"
          v-for="item of detailsList"
          :key="item.id"
        >
          <el-descriptions-item label="商户订单号">{{
            item.merchantChargeNo
          }}</el-descriptions-item>
          <el-descriptions-item label="退款金额/元">{{
            item.fmtRefundAmount
          }}</el-descriptions-item>
          <el-descriptions-item label="退款理由">{{
            item.refundRemark
          }}</el-descriptions-item>
          <el-descriptions-item label="退款申请时间">{{
            item.gmtCreated
          }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          @click="batchEdit('fail_approval', batchNo)"
          type="danger"
          style="width: 100px"
          >拒绝</el-button
        >
        <el-button
          type="primary"
          @click="batchEdit('success_approval', batchNo)"
          style="width: 100px"
          >同意</el-button
        >
      </span>
    </el-dialog>
    <!-- 详情抽屉 -->
    <detail-drawer
      :drawer.sync="drawer"
      :info="detailsInfo"
      :activeKey="tabRefundIndex"
    ></detail-drawer>
  </div>
</template>

<script>
import detailDrawer from "./detailDrawer.vue";
import { setTabIndex, getTabIndex } from "@/utils/public";
import mixin from "@/mixins/mixin";
export default {
  mixins: [mixin],
  components: {
    detailDrawer,
  },
  name: "refundVue",
  data() {
    return {
      tabRefundIndex:'1',
      auditInfo: {},
      eventTab: "1",
      buttonRole: false,
      btnShow: false,
      auditStatusType: "",
      detailsVisible: false,
      activeKey: getTabIndex(),
      detailsInfo: {},
      drawer: false,
      mixinViewModuleOptions: {
        getDataListURL: "/api/refund/audit/page/waiting/single",
        createdIsNeed: false,
      },
      dataList: [],
      refundStateList: [
        { id: 1, label: "所有", value: "" },
        { id: 2, label: "审核通过", value: "success_approval" },
        { id: 3, label: "审核拒绝", value: "fail_approval" },
      ],
      commandForm: {
        dateType: "1",
        date: [],
        status: "",
        searchVal: "",
      },
      id: null,
      multipleSelection: [],
      isAgreeAll: false,
      batchNo: null,
      detailsList: [],
    };
  },
  created() {
    if (this.$store.state.buttonList) {
      this.$store.state.buttonList.forEach((e) => {
        if (e.type == "refundApply") {
          this.buttonRole = true;
        }
      });
    }
  },
  mounted() {
    this.handleTab();
  },
  watch: {
    "$store.state.testLine": {
      handler() {
        if (this.$route.name == this.$options.name) {
          if (this.eventTab == "1") {
            this.handleQuery();
          } else {
            this.globalQuery();
          }
        }
      },
    },
    deep: true,
  },
  methods: {
    getTabIndex,
    exchangeEventTab() {
      if (this.eventTab == "1") {
        this.eventTab = "2";
        if (this.tabRefundIndex === "2") {
        this.commandForm = {
          batchNo: this.commandForm.searchVal,
        };
      } else {
        this.commandForm = {
          merchantChargeNo: this.commandForm.searchVal,
        };
      }
      this.dataForm=JSON.parse(JSON.stringify(this.commandForm))
        this.globalQuery();
      } else {
        this.eventTab = "1";
        this.commandForm = {
        dateType:"1",
        date: [],
        status: "",
        };
        this.dataForm=JSON.parse(JSON.stringify(this.commandForm))
        this.handleQuery();
      }
    },
    tabRefundFn(val){
      this.btnShow=false
      this.dataList=[]
this.tabRefundIndex=val
if (this.eventTab == "1") {
   this.handleQuery();
   } else {
    if (this.tabRefundIndex === "2") {
        this.commandForm = {
          batchNo: '',
        };
      } else {
        this.commandForm = {
          merchantChargeNo: '',
        };
      }
      this.dataForm=JSON.parse(JSON.stringify(this.commandForm))
   this.globalQuery();
    }
    },
    handleDetails(rowData) {
      switch (this.tabRefundIndex) {
        case "1":
          this.$http
            .get(`/api/refund/audit/detail/single?id=${rowData.id}`)
            .then((res) => {
              if (res.code === "0000") {
                this.detailsInfo = res.data;
                this.drawer = true;
              }
            });
          break;
        case "2":
          this.$http
            .get(
              `/api/refund/audit/detail/batch?id=${rowData.id}`
            )
            .then((res) => {
              if (res.code === "0000") {
                this.detailsInfo = res.data;
                this.drawer = true;
              }
            });

          break;
        default:
          break;
      }
    },
    handleTab() {
      this.dataList=[]
      this.tabRefundIndex='1'
      setTabIndex(this.activeKey);
      this.pageSize = 10;
      this.resetForm("refundForm");
      this.commandForm = {
        dateType:"1",
        date: [],
        status: "",
        searchVal:'',
      };
      this.btnShow = false;
      this.dataForm=JSON.parse(JSON.stringify(this.commandForm))
      this.handleQuery();
    },
    handleAudit(row, type) {
      this.id = row.id;
      if (type === "success_approval") {
        let that = this;
        that
          .$confirm(
            "确认退款后，退款金额将于7个工作日内原路原回。",
            "同意退款",
            {
              customClass: "confirm",
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              showClose: false,
              closeOnClickModal: false,
              closeOnPressEscape: false,
              type: "warning",
              center: true,
            }
          )
          .then(() => {
            that.handleOk();
          });
        that.isAgreeAll = false;
      } else {
        let that = this;
        that
          .$confirm(
            "确认拒绝该笔退款申请吗？拒绝后该笔及相关订单状态不变，退款订单也不会生成相关记录。",
            "拒绝退款",
            {
              customClass: "confirm",
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              showClose: false,
              closeOnClickModal: false,
              closeOnPressEscape: false,
              type: "warning",
              center: true,
            }
          )
          .then(() => {
            that.agreeRefund("fail_approval");
          });
      }
    },
    handleOk() {
      if (this.isAgreeAll) {
        this.refundAll1("success_approval", this.multipleSelection);
      } else {
        this.agreeRefund("success_approval");
      }
    },
    getAllList() {
      this.$http
        .post("/api/merchant/refundAudit/searchBatchByPage", {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          params: {},
        })
        .then((res) => {
          if (res.code === "0000") {
            this.dataList = res.data.list;
            this.total = res.data.total;
          } else {
            this.dataList = [];
            this.total = 0;
          }
        });
    },
    agreeRefund(type) {
      let params = {
        status: type,
        remark:"",
        id: this.id,
      };
      this.$http.post("/api/refund/audit/approve/single", params).then((res) => {
        if (res.code === "0000") {
          this.$message.success("提交成功");
          this.getData();
        }
      });
    },
    globalQuery() {
      this.eventTab = "2";
      this.getData();
    },
    handleQuery() {
      this.eventTab = "1";
      this.dataForm.batchNo = "";
      this.dataForm.merchantChargeNo = "";
      if (this.dataForm.date && this.dataForm.date.length) {
        if (this.dataForm.dateType === "1") {
          this.dataForm.startTime = this.dataForm.date[0];
          this.dataForm.endTime = this.dataForm.date[1];
        } else {
          this.dataForm.startAuditTime = this.dataForm.date[0];
          this.dataForm.endAuditTime = this.dataForm.date[1];
        }
      } else {
        this.dataForm.startAuditTime = "";
        this.dataForm.startAuditTime = "";
        this.dataForm.startTime = "";
        this.dataForm.endTime = "";
      }
      this.getData();
    },
    getData() {
      if (this.activeKey == "1") {
        if(this.tabRefundIndex=='1'){
          this.mixinViewModuleOptions.getDataListURL =
          "/api/refund/audit/page/waiting/single";
        }else{
          this.mixinViewModuleOptions.getDataListURL =
          "/api/refund/audit/page/waiting/batch";
        }
        this.getAuditStatistics();
      } else {
        if(this.tabRefundIndex=='1'){
          this.mixinViewModuleOptions.getDataListURL =
          "/api/refund/audit/page/finish/single";
        }else{
          this.mixinViewModuleOptions.getDataListURL =
          "/api/refund/audit/page/finish/batch";
        }
        this.getBatchAuditStatistics();
      }
      this.getDataList();
    },
    getAuditStatistics() {
      this.$http
        .post("/api/refund/audit/statistics/wait", this.dataForm)
        .then((res) => {
          if (res.code == "0000") {
            this.auditInfo = res.data;
          }
        });
    },
    getBatchAuditStatistics() {
      this.$http
        .post(
          "/api/refund/audit/statistics/finish",
          this.dataForm
        )
        .then((res) => {
          if (res.code == "0000") {
            this.auditInfo = res.data;
          }
        });
    },
    batchEdit(type, id) {
      let that = this;
      that
        .$confirm(
          `${
            type == "success_approval"
              ? "确认退款后，退款金额将于7个工作日内原路原回。"
              : "确认拒绝该笔退款申请吗？拒绝后该笔及相关订单状态不变，退款订单也不会生成相关记录。"
          }`,
          `${type == "success_approval" ? "同意退款" : "拒绝退款"}`,
          {
            customClass: "confirm",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            showClose: false,
            closeOnClickModal: false,
            closeOnPressEscape: false,
            type: "warning",
            center: true,
          }
        )
        .then(() => {
          that.refundAll(type, id);
        });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val.map((item) => item.id);
    },
    batchAudit(type, isagree = false) {
      if (this.multipleSelection.length === 0) {
        return this.$message.warning("请先选择退款订单");
      }
      if (isagree) {
        let that = this;
        that
          .$confirm(
            "确认退款后，退款金额将于7个工作日内原路原回。",
            "同意退款",
            {
              customClass: "confirm",
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              showClose: false,
              closeOnClickModal: false,
              closeOnPressEscape: false,
              type: "warning",
              center: true,
            }
          )
          .then(() => {
            that.handleOk();
          });
        that.isAgreeAll = true;
      } else {
        let that = this;
        that
          .$confirm(
            "确认拒绝该笔退款申请吗？拒绝后该笔及相关订单状态不变，退款订单也不会生成相关记录。",
            "拒绝退款",
            {
              customClass: "confirm",
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              showClose: false,
              closeOnClickModal: false,
              closeOnPressEscape: false,
              type: "warning",
              center: true,
            }
          )
          .then(() => {
            that.refundAll1(type, that.multipleSelection);
          });
      }
    },
    refundAll(type, id) {
      let params = {
        status: type,
        id:id,
        remark:''
      };
      this.$http
        .post("/api/refund/audit/approve/single", params)
        .then((res) => {
          if (res.code === "0000") {
            this.$message.success("提交成功");
            this.detailsVisible = false;
            this.getData();
          }
        });
    },
    refundAll1(type, ids = []) {
      this.$http
        .post("/api/refund/audit/approve/batch", {
          status: type,
          remark:'',
          ids,
        })
        .then((res) => {
          if (res.code === "0000") {
            this.$message.success("提交成功");
            this.getData();
          }
        });
    },
    showDetails(id, type) {
      this.batchNo = id;
      this.auditStatusType = type;
      this.detailsVisible = true;
      this.$http
        .get(`/api/merchant/refundAudit/listOrderByBatchId?batchNo=${id}`)
        .then((res) => {
          if (res.code === "0000") {
            this.detailsList = res.data;
          } else {
            this.detailsList = [];
          }
        });
    },
  },
};
</script>

<style scoped lang="scss">
.tabWrap {
  height: 133px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  .search {
    width: 466px;
  }
  .backWrap {
    height: 20px;
    position: absolute;
    bottom: 8px;
    right: 10px;
    display: flex;
    align-items: center;
    cursor: pointer;
    span {
      display: inline-block;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #03bfc6;
      margin-right: 10px;
    }
  }
}
.textBox {
  margin: 20px 0;
}
.switch {
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ml {
  margin-left: 20px;
}
.detailscss {
  .title {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 30px;
  }
  .tag {
    height: 34px;
    background: #f4f8fb;
    color: #869daa;
    line-height: 34px;
    padding-left: 20px;
  }
  .batchNo {
    color: #4f595f;
    margin-left: 20px;
  }
}
.dialogText {
  display: flex;
  .dialogTitle {
    font-size: 18px;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.85);
    line-height: 24px;
    font-weight: 500;
  }
  .explain {
    color: rgba(0, 0, 0, 0.6);
    line-height: 22px;
    margin: 10px 0;
  }
}
:deep(.el-descriptions) {
  padding: 20px 20px 0;
  .el-descriptions-item__label {
    color: #869daa;
  }
}
:deep(.el-dialog) {
  border-radius: 16px;
  .el-dialog__header {
    padding: 0;
  }
  .el-icon-warning {
    font-size: 18px;
    color: #faad14;
    margin-top: 4px;
    margin-right: 17px;
  }
}
:deep(.leftSe) {
  .el-input__inner {
    border-radius: 4px 0 0 4px;
  }
}
.title {
  color: #4f595f;
  position: relative;
  font-size: 18px;
  font-weight: 500;
  line-height: 34px;
  margin-left: 10px;
}
.textBox {
  display: flex;
  .label {
    color: #869daa;
    font-size: 14px;
    width: 120px;
    margin-left: 10px;
    text-align: right;
  }
  .val {
    font-size: 14px;
    margin-left: 20px;

    color: #869daa;
    width: 700px;
  }
}
:deep(.search) {
  .el-input__inner {
    border-radius: 2px 0 0 2px;
    height: 38px;
    line-height: 38px;
  }
}
:deep(.searBtn) {
  .el-button--small {
    border-radius: 0 2px 2px 0;
    padding: 12px 24px;
  }
}
.allbtn{
  border:1px solid #03BFC6;background: rgba(3,191,198,0.03);color:#03BFC6
}
</style>
